/**
 * 
 */
package com.cats.adapter;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.cats.R;
import com.cats.model.ShipmentUpdateModel;

/**
 * @author Jason
 *
 */
public class ShipmentAdapter extends ArrayAdapter<ShipmentUpdateModel> {

	    Context context;
	    int layoutResourceId;
	    ArrayList<ShipmentUpdateModel> datas = null;

		public ShipmentAdapter(Context context, int textViewResourceId,
				List<ShipmentUpdateModel> objects) {
			super(context, textViewResourceId, objects);
	        this.layoutResourceId = textViewResourceId;
	        this.context = context;
	        this.datas = (ArrayList<ShipmentUpdateModel>) objects;
	        System.out.println("[ShipmentAdapter]datas count:" + this.datas.size());
	    }

	    @Override
	    public View getView(int position, View convertView, ViewGroup parent) {
	        View row = convertView;
	        Holder holder = null;
	       
	        if(row == null)
	        {
	            LayoutInflater inflater = ((Activity)context).getLayoutInflater();
	            row = inflater.inflate(layoutResourceId, parent, false);
	           
	            holder = new Holder();
	            holder.txtTimeTextView = (TextView)row.findViewById(R.id.txtTime);
	            holder.txtCommentTextView = (TextView)row.findViewById(R.id.txtUpdate);
	           
	            row.setTag(holder);
	        }
	        else
	        {
	            holder = (Holder)row.getTag();
	        }
	       
	        ShipmentUpdateModel update = this.datas.get(position);
	        holder.txtTimeTextView.setText(update.getTimeString());
	        holder.txtCommentTextView.setText(update.getCommentString());
	        
	        System.out.println("[ShipmentAdapter]getView()");
	       
	        return row;
	    }
	   
	    static class Holder
	    {
	        TextView txtTimeTextView;
	        TextView txtCommentTextView;
	    }
}
